<?php
    header("content-type:text/html;charset=utf-8");
    $config = include_once('../../public/config/config.php');
    include_once('../../public/func/db.php');
    include_once('../../public/func/shangchuan.func.php');
    $table = 'article';
    $filename = '../../public/upload';
    $_POST['ctime'] = time();
    $_POST['status'] = '已审核';
    $_POST['kid'] = $_POST['colId'];
    $arr = select($config,'kinds','where id='.$_POST['kid']);
    $arr[0]['articlenum'] += 1;
    update($config,'kinds',$arr[0]);
    $_POST['pic'] = shangchuan($_FILES['pic'],$filename);
    if($_POST['pic'] == '没有文件被上传'){
        $_POST['pic'] = 'default.jpg';
    }
    if(empty($_POST['kid'])){
        die("<script>alert('请选择类别！');window.location.href='addarticle.php'</script>");
    }else if(empty($_POST['title'])){
        die("<script>alert('标题不能为空');window.location.href='addarticle.php'</script>");
    }else if(empty($_POST['uid'])){
        die("<script>alert('作者不能为空');window.location.href='addarticle.php'</script>");
    }else if(empty($_POST['content'])){
        die("<script>alert('内容不能为空');window.location.href='addarticle.php'</script>");
    }
    $res = insert($config,$table,$_POST);
    if(!empty($res)){
        echo "<script>alert('添加失败');window.location.href='addarticle.php'</script>";
    }else{
        echo "<script>alert('添加成功');window.location.href='article.php'</script>";
    }
?>